package com.yztstudy.Controller;

import com.yztstudy.Service.ProductService;
import com.yztstudy.param.ProductCollectParam;
import com.yztstudy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品被收藏的表示层
 */

@RestController
@RequestMapping("/product")
public class ProductCollectController {

    @Autowired
    private ProductService productService;

    /**
     * TODO 根据商品ID集合查询多个商品
     * @param productCollectParam 商品ID的集合
     * @param result 校验的结果
     * @return
     */
    @PostMapping("/collect/list")
    public R productIds(@RequestBody @Validated ProductCollectParam productCollectParam, BindingResult result)
    {
        // TODO 1.如果校验失败
        if (result.hasErrors())
        {
            return R.ok("没有收藏的商品!");
        }

        // TODO 2.如果校验成功,就交给业务逻辑层处理
        return productService.productIds(productCollectParam);
    }
}
